<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/Huploadify/Huploadify.css"/>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/jquery-ui-1.10.4.custom.min.js"></script>
    <style>
        input.error{
            border:1px solid red;
        }
        span.error{
            padding-top:10px;
            color: #f00;
            font-size:12px;
        }
        .remarks{
            color:#ff0000;
            font-size: 16px;
        }
        .spec_item_thumb{
            position: relative;
        }
        .spec_item_thumb i {
            position: absolute;
            top: -5px;
            right: -5px;
        }
    </style>
</head>

<script>
    {if condition="isset($pum)"}
    var pnum = {$pnum};
    {else/}
    var pnum = 1;
    {/if}
    {if condition="isset($filter)"}
    var filter = {$filter};
    {else/}
    var filter = 0;
    {/if}

    {if condition="!isset($search) && !isset($cate_id)"}
    var url = "/{$Request.module}/goods/lst/filter/"+filter+".html?page="+pnum;
    {elseif condition="isset($search) && $search" /}
    var url = "/{$Request.module}/goods/search.html?page="+pnum;
    {elseif condition="isset($cate_id) && $cate_id" /}
    var cate_id = {$cate_id};
    var url = "/{$Request.module}/goods/catelist/cate_id/"+cate_id+"/filter/"+filter+".html?page="+pnum;
    {/if}
    var updateUrl = "{:url('goods/post')}";
</script>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑商品</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" enctype="multipart/form-data" class="form-horizontal" id="form">
                        <div class="tabs-container">
                            <ul class="nav nav-tabs">
                                <li class="active"><a data-toggle="tab" href="#tab_basic" aria-expanded="true">基本信息</a></li>
                                <li class=""><a data-toggle="tab" href="#tab_option" aria-expanded="false">库存/规格</a></li>
                                <li class=""><a data-toggle="tab" href="#tab_param" aria-expanded="false">参数</a></li>
                                <li class=""><a data-toggle="tab" href="#tab_des" aria-expanded="false">商品详情</a></li>
                                <li class="" id="li_dispatch"><a data-toggle="tab" href="#tab_dispatch" aria-expanded="false">物流设置</a></li>
                                <li class=""><a data-toggle="tab" href="#tab_pic" aria-expanded="false">商品图片</a></li>
                                <li class="" id="li_offline"><a data-toggle="tab" href="#offline" aria-expanded="false">线下核销</a></li>
                            </ul>
                            <div class="tab-content">
                                <div id="tab_basic" class="tab-pane active">{include file="goods/tab/basic"/}</div>
                                <div id="tab_option" class="tab-pane">{include file="goods/tab/option"/}</div>
                                <div id="tab_param" class="tab-pane">{include file="goods/tab/param"/}</div>
                                <div id="tab_des" class="tab-pane">{include file="goods/tab/des"/}</div>
                                <div id="tab_dispatch" class="tab-pane">{include file="goods/tab/dispatch"/}</div>
                                <div id="tab_pic" class="tab-pane">{include file="goods/tab/pic"/}</div>
                                <div id="offline" class="tab-pane">{include file="goods/tab/offline"/}</div>
                            </div>

                            <input name="id" type="hidden" value="{$goodss.id}" >

                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2" style="margin-top:20px; margin-left:0%;">
                                <button class="btn btn-primary" type="submit" id="doSubmit">保存内容</button>
                                <button class="btn btn-primary" type="button" onclick="goBackLst('/{$Request.module}/goods/lst');">返回</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->

<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script type="text/javascript" src="__PUBLIC__/admin/Huploadify/jquery.Huploadify.js"></script>
<script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="__PUBLIC__/admin/js/common/ajax.js"></script>

<script type="text/javascript">
    //实例化编辑器
    UE.getEditor('goods_desc', {initialFrameWidth:'100%', initialFrameHeight:500});
</script>

<script>



    $(function(){
        var goods_type = {if condition="isset($goodss['goods_type'])"}{$goodss['goods_type']}{else/}1{/if};
        if(goods_type == 2){
            $("#li_dispatch").css("display","none");
        }
        $("input[name='goods_type']").eq(goods_type-1).attr("checked",'true');
        var entity_check = {if condition="isset($goodss['entity_check'])"}{$goodss['entity_check']}{else/}0{/if};
        if(entity_check == 1){
            $("input[name='entity_check']").attr("checked",'true');
            $("#li_offline").css("display","block");
        }else{
            $("#li_offline").css("display","none");
        }

        $('input[name=entity_check]').click(function(){
            var entity_check = $('input:checkbox[name="entity_check"]:checked').val();
            if(entity_check == 1){
                $("#li_offline").css("display","block");
            }else{
                $("#li_offline").css("display","none");
            }
        });

        $('input[name=goods_type]').click(function(){
            var goods_type = $('input:radio[name="goods_type"]:checked').val();
            if(goods_type == 2){
                $("#li_offline").css("display","block");
                $("#li_dispatch").css("display","none");
            }else{
                var entity_check = $('input:checkbox[name="entity_check"]:checked').val();
                if(entity_check == 1){
                    $("#li_offline").css("display","block");
                }else{
                    $("#li_offline").css("display","none");
                }
                $("#li_dispatch").css("display","block");
            }
        });


        $('select[name=cate_id]').change(function(){
            var cate_id = $(this).val();
            $('#attr').empty();
            if(cate_id != ''){
                $.ajax({
                    url:"{:url('goods/getbrandtype')}",
                    type:'POST',
                    data:{'cate_id':cate_id},
                    dataType:'json',
                    success:function(data){
                        if(data){
                            if(data.brandres){
                                var html = '';
                                html+='<option value="">请选择</option>';
                                $.each(data.brandres,function(i,v){
                                    html+='<option value="'+v.id+'">'+v.brand_name+'</option>';
                                });
                                $('#brand_id').html(html);
                            }else{
                                var html='<option value="">请选择</option>';
                                $('#brand_id').html(html);
                            }


                        }
                    }
                });
            }else{
                var html='<option value="">请选择</option>';
                $('#brand_id').html(html);
                $('#type_id').html(html);
            }
        });


        //上传缩略图
        $('#uploaderInput').Huploadify({
            uploader : '{:url("Common/Upload/uploadPic")}',
            method:'post',
            formData:{name:'goods_thumb'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
            buttonText : '上传图像',
            removeTimeout: 2000,
            fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileObjName: 'file', //上传附件$_FILE标识
            fileSizeLimit : 2048,
            //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            auto : true, //开启,自动上传
            multi : false, //开启,多选文件
            //开始上传
            onUploadStart:function(file){
                layer.load(2);
            },
            onUploadSuccess : function(file, data, response) {
                //解析成json对象
                eval('var data='+data);
                if(data.status == 200){
                    var picpath = data.data.path;
                    $('#imageinfo').attr('src',picpath);
                    $('.del').show();
                    $('input[name=goods_thumb]').val(picpath);
                }else{
                    layer.msg(data.mess, {icon: 2,time: 2000});
                }
            },
            //上传完成后执行的操作
            onUploadComplete:function(file){
                layer.closeAll('loading');
            },
            //上传错误
            onUploadError : function(file, errorCode, errorMsg, errorString) {
                layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
            }
        });


        $('.del').click(function(){
            $('input[name=goods_thumb]').val('');
            var picval = $('.goods_thumb').text();
            if(picval != ''){
                $('#imageinfo').attr('src',picval);
            }else{
                $('#imageinfo').attr('src','__PUBLIC__/admin/img/nopic.jpg');
            }
            $('.del').hide();
        });

        //批量上传广告图片
        $('#uploaderInputs').Huploadify({
            uploader : '{:url("Common/Upload/uploadPic")}',
            method:'post',
            formData:{name:'goods_pic'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
            buttonText : '上传图像',
            removeTimeout: 2000,
            fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileObjName: 'file', //上传附件$_FILE标识
            fileSizeLimit : 2048,
            //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            auto : true, //开启,自动上传
            multi : false, //开启,多选文件
            //开始上传
            onUploadStart:function(file){
                layer.load(2);
            },
            onUploadSuccess : function(file, data, response) {
                //解析成json对象
                eval('var data='+data);
                if(data.status == 200){
                    var picpath = data.data.path;
                    var img = '<div class="imgli" style="width:170px; height:250px; margin-right:10px; margin-bottom:10px; float:left;"><img class="image" src="'+picpath+'" width="150" height="100" border="0" /><br/><button type="button" class="btn btn-danger btn-xs" onclick="deletegp(this);">删除</button><input class="pic_id" type="hidden" name="goods_pics[]" value="'+picpath+'"><div style="margin-top:15px;">排序:<input type="text" name="sort3[]"></div></div>';
                    $('.imglst').append(img);
                }else{
                    layer.msg(data.mess, {icon: 2,time: 2000});
                }
            },
            //队列完成后执行的操作
            onQueueComplete:function(file){
                layer.closeAll('loading');
            },
            //上传错误
            onUploadError : function(file, errorCode, errorMsg, errorString) {
                layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
            }
        });

        $('select[name=type_id]').change(function(){
            var type_id = $(this).val();
            var id = $('input[name=id]').val();
            var cate_id = $('#cate_id option:selected').val();

            if(type_id == ''){
                $('#attr').empty();
                return false;
            }

            if(cate_id == ''){
                $('#attr').empty();
                return false;
            }

            $.ajax({
                url:'{:url("goods/getAttrLst")}',
                type:'POST',
                data:{'type_id':type_id,'id':id,'cate_id':cate_id},
                dataType:'json',
                success:function(data){
                    if(data){
                        var html = '';
                        $.each(data['attrres'],function(index,value){
                            if(value['attr_type'] == 0){
                                if(value['attr_values'] == ''){
                                    if(data['gares'][value['id']]){
                                        html+='<div class="form-group"><label class="col-sm-2 control-label" style="padding-top:12px;">'+value['attr_name']+'</label><div class="col-sm-7"><input type="text" name="goods_attr['+value['id']+'][attr_value]" value="'+data['gares'][value['id']][0]['attr_value']+'" class="form-control"><input type="hidden" name="goods_attr['+value['id']+'][id]" value="'+data['gares'][value['id']][0]['id']+'"></div></div><div class="hr-line-dashed"></div>';
                                    }else{
                                        html+='<div class="form-group"><label class="col-sm-2 control-label" style="padding-top:12px;">'+value['attr_name']+'</label><div class="col-sm-7"><input type="text" name="goods_attr['+value['id']+'][attr_value]" class="form-control"></div></div><div class="hr-line-dashed"></div>';
                                    }
                                }else{
                                    var attrs = value.attr_values.split(',');
                                    html+='<div class="form-group"><label class="col-sm-2 control-label">'+value['attr_name']+'</label><div class="col-sm-7"><select class="form-control m-b" name="goods_attr['+value['id']+'][attr_value]"><option value="">请选择</option>';
                                    for(var i=0; i<attrs.length; i++){
                                        if(data['gares'][value['id']] && data['gares'][value['id']][0]['attr_value'] == attrs[i]){
                                            html+='<option value="'+attrs[i]+'" selected="selected">'+attrs[i]+'</option>';
                                        }else{
                                            html+='<option value="'+attrs[i]+'">'+attrs[i]+'</option>';
                                        }
                                    }
                                    if(data['gares'][value['id']]){
                                        html+='</select></div><input type="hidden" name="goods_attr['+value['id']+'][id]" value="'+data['gares'][value['id']][0]['id']+'"></div><div class="hr-line-dashed"></div>';
                                    }else{
                                        html+='</select></div></div><div class="hr-line-dashed"></div>';
                                    }
                                }
                            }else if(value['attr_type'] == 1){
                                var attrs = value.attr_values.split(',');
                                if(data['gares'][value['id']]){
                                    html+='<div class="attrgroup">';
                                    $.each(data['gares'][value['id']],function(i,v){
                                        if(i==0){
                                            html+='<div class="form-group"><label class="col-sm-2 control-label" style="padding-top:12px;"><a href="javascript:;" onclick="attrad(this);">[+]</a>'+value['attr_name']+'</label><div class="col-sm-4"><div style="padding:5px;position:relative;" class="col-sm-12"><span style="position:absolute;top:5px;overflow:hidden;width:95%;height:34px;"><select onchange="xzshuxing(this);" class="form-control m-b" name="xzshuxing['+value['id']+'][attr_value][]"><option value="">请选择</option>';
                                        }else{
                                            html+='<div class="form-group"><label class="col-sm-2 control-label" style="padding-top:12px;"><a href="javascript:;" onclick="attrad(this);">[-]</a>'+value['attr_name']+'</label><div class="col-sm-4"><div style="padding:5px;position:relative;" class="col-sm-12"><span style="position:absolute;top:5px;overflow:hidden;width:95%;height:34px;"><select onchange="xzshuxing(this);" class="form-control m-b" name="xzshuxing['+value['id']+'][attr_value][]"><option value="">请选择</option>';
                                        }
                                        for(var i=0; i<attrs.length; i++){
                                            if(v['attr_value'] == attrs[i]){
                                                html+='<option value="'+attrs[i]+'" selected="selected">'+attrs[i]+'</option>';
                                            }else{
                                                html+='<option value="'+attrs[i]+'">'+attrs[i]+'</option>';
                                            }
                                        }
                                        html+='</select></span><span style="position:absolute;top:7px;left:10px;margin-top:1px;margin-left:1px;width:80%;height:28px;border-radius:5px;"><input type="text" name="goods_attr['+value['id']+'][attr_value][]" value="'+v['attr_value']+'" class="ccdd" placeholder="可选择也可自定义" style="width:80%;height:24px;border:0pt;border-radius:5px;outline:0"></span></div></div><input type="hidden" class="gaid" name="goods_attr['+value['id']+'][id][]" value="'+v['id']+'"><label class="col-sm-1 control-label" style="width:7%;">价格+</label><div class="col-sm-1" style="width:15%;"><input type="text" name="goods_attr['+value['id']+'][attr_price][]" class="form-control" value="'+v['attr_price']+'"></div>';
                                        if(value['is_upload'] == 1){
                                            html+='<div class="col-sm-2 is_upload" style="width:15%;">';
                                            if(v['attr_pic']){
                                                html+='<img class="attrimg" src="/'+v['attr_pic']+'" width="60px" height="60px" border="0" style="float:left;margin-right:10px;" />';
                                            }else{
                                                html+='<img class="attrimg" src="/static/admin/img/nopic.jpg" width="60px" height="60px" border="0" style="float:left;margin-right:10px;" />';
                                            }
                                            html+='<div class="uploaderattr"><button type="button" class="btn btn-info btn-sm" onclick="upattrpic(this);">上传图像</button></div><button type="button" class="btn btn-danger btn-xs delpic" onclick="delattrpic(this)" style="display:none;">删除</button><input type="hidden" class="attrpic_id" name="goods_attr['+value['id']+'][attrpic_id][]" value="">';
                                            if(v['attr_pic']){
                                                html+='<div class="repicm" style="display:none;">'+v['attr_pic']+'</div>';
                                            }else{
                                                html+='<div class="repicm" style="display:none;"></div>';
                                            }
                                        }
                                        html+='</div></div>';
                                    });
                                    html+='</div><div class="hr-line-dashed"></div>';
                                }else{
                                    var attrs = value.attr_values.split(',');
                                    html+='<div class="attrgroup"><div class="form-group"><label class="col-sm-2 control-label" style="padding-top:12px;"><a href="javascript:;" onclick="attrad(this);">[+]</a>'+value['attr_name']+'</label><div class="col-sm-4"><div style="padding:5px;position:relative;" class="col-sm-12"><span style="position:absolute;top:5px;overflow:hidden;width:95%;height:34px;"><select onchange="xzshuxing(this);" class="form-control m-b" name="xzshuxing['+value['id']+'][attr_value][]"><option value="">请选择</option>';
                                    for(var i=0; i<attrs.length; i++){
                                        html+='<option value="'+attrs[i]+'">'+attrs[i]+'</option>';
                                    }
                                    html+='</select></span><span style="position:absolute;top:7px;left:10px;margin-top:1px;margin-left:1px;width:80%;height:28px;border-radius:5px;"><input type="text" name="goods_attr['+value['id']+'][attr_value][]" class="ccdd" placeholder="可选择也可自定义" style="width:80%;height:24px;border:0pt;border-radius:5px;outline:0"></span></div></div><label class="col-sm-1 control-label" style="width:7%;">价格+</label><div class="col-sm-1" style="width:15%;"><input type="text" name="goods_attr['+value['id']+'][attr_price][]" class="form-control" value="0"></div>';
                                    if(value['is_upload'] == 1){
                                        html+='<div class="col-sm-2 is_upload" style="width:15%;"><img class="attrimg" src="/static/admin/img/nopic.jpg" width="60px" height="60px" border="0" style="float:left;margin-right:10px;" /><div class="uploaderattr"><button type="button" class="btn btn-info btn-sm" onclick="upattrpic(this);">上传图像</button></div><button type="button" class="btn btn-danger btn-xs delpic" onclick="delattrpic(this)" style="display:none;">删除</button><input type="hidden" class="attrpic_id" name="goods_attr['+value['id']+'][attrpic_id][]" value=""><div class="repicm" style="display:none;"></div></div>';
                                    }
                                    html+='</div></div><div class="hr-line-dashed"></div>';
                                }
                            }
                        });
                        $('#attr').html(html);
                    }else{
                        layer.msg('获取信息失败', {icon: 2,time: 2000});
                    }
                },
                error:function(){
                    layer.msg('操作失败，请重试', {icon: 2,time: 2000});
                }
            });
        });

        var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        $('#form').validate({
            errorElement : 'span',
            debug: true,//只验证不提交表单
            //layer ajax提交表单
            submitHandler:function(){
                full = checkoption();
                if (!full) {
                    layer.msg('请输入规格名称!',{icon:2});
                    return false;
                }
                optionArray();
                // return false;
                post(updateUrl,'POST',$('#form').serialize(),1);
                return false;
            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

            rules:{
                goods_name:{required:true},
                cate_id:{required:true},
                shcate_id:{required:true},
                market_price:{required:true},
                shop_price:{required:true},
                search_keywords:{required:true},
                goods_desc:{required:true},
                // type_id:{required:true}
            },

            messages:{
                goods_name:{required:icon+'必填'},
                cate_id:{required:icon+'必选'},
                shcate_id:{required:icon+'必选'},
                market_price:{required:icon+'必填'},
                shop_price:{required:icon+'必填'},
                search_keywords:{required:icon+'必填'},
                goods_desc:{required:icon+'商品详情必填'},
                // type_id:{required:icon+'必选'}
            }
        });
    });

    function checkoption() {

        var full = true;
        var $spec_title = $(".spec_title");
        var $spec_item_title = $(".spec_item_title");
        if ($("#hasoption").get(0).checked) {
            if($spec_title.length==0){

                full = false;
            }
            if($spec_item_title.length==0){

                full = false;
            }
        }
        if (!full) {
            return false;
        }
        return full;
    }

    function optionArray()
    {
        var option_stock = new Array();
        $('.option_stock').each(function (index,item) {
            option_stock.push($(item).val());
        });

        var option_id = new Array();
        $('.option_id').each(function (index,item) {
            option_id.push($(item).val());
        });

        var option_ids = new Array();
        $('.option_ids').each(function (index,item) {
            option_ids.push($(item).val());
        });

        var option_title = new Array();
        $('.option_title').each(function (index,item) {
            option_title.push($(item).val());
        });

        var option_virtual = new Array();
        $('.option_virtual').each(function (index,item) {
            option_virtual.push($(item).val());
        });

        var option_marketprice = new Array();
        $('.option_marketprice').each(function (index,item) {
            option_marketprice.push($(item).val());
        });
        var option_presellprice = new Array();
        $('.option_presell').each(function (index,item) {
            option_presellprice.push($(item).val());
        });

        var option_productprice = new Array();
        $('.option_productprice').each(function (index,item) {
            option_productprice.push($(item).val());
        });

        var option_costprice = new Array();
        $('.option_costprice').each(function (index,item) {
            option_costprice.push($(item).val());
        });

        var option_goodssn = new Array();
        $('.option_goodssn').each(function (index,item) {
            option_goodssn.push($(item).val());
        });

        var option_productsn = new Array();
        $('.option_productsn').each(function (index,item) {
            option_productsn.push($(item).val());
        });

        var option_weight = new Array();
        $('.option_weight').each(function (index,item) {
            option_weight.push($(item).val());
        });

        var options = {
            option_stock : option_stock,
            option_id : option_id,
            option_ids : option_ids,
            option_title : option_title,

            option_marketprice : option_marketprice,
            option_productprice : option_productprice,

            option_goodssn : option_goodssn,
            option_productsn : option_productsn,
            option_weight : option_weight,

        };
        $("input[name='optionArray']").val(JSON.stringify(options));
    }




    //删除商品图片批量上传临时文件
    function deletegp(obj){
        var div = $(obj).parent();
        var ypic_id = div.find('input[class=ypic_id]').val();
        var pic_id = div.find('input[class=pic_id]').val();
        var goods_id = $('input[name=id]').val();
        if(ypic_id){
            layer.confirm('该图片已存在，确定彻底删除？', {
                skin: 'layui-layer-molv',
                closeBtn: 0,
                shadeClose : true,
                btn: ['确定','取消'] //按钮
            },function(){
                layer.load(2);
                $.ajax({
                    url:"{:url('goods/deleteone')}",
                    type:'POST',
                    data:{'ypic_id':ypic_id,'goods_id':goods_id},
                    dataType:'json',
                    success:function(data){
                        if(data == 1){
                            layer.closeAll('loading');
                            layer.msg('删除成功', {icon: 1,time: 1000}, function(){
                                div.remove();
                            });
                        }else{
                            layer.closeAll('loading');
                            layer.msg('删除图片失败', {icon: 2,time: 1000});
                        }
                    },
                    error:function(){
                        layer.closeAll('loading');
                        layer.msg('操作失败，请重试', {icon: 2,time: 2000});
                    }
                });
            });
        }else if(pic_id){
            div.remove();
        }
    }


    //商品单选属性设置多个
    function attrad(obj){
        var div = $(obj).parent().parent();
        var group = $(obj).parent().parent().parent();
        var gaid = div.find('input[class=gaid]').val();
        if($(obj).html() == '[+]'){
            var newdiv = div.clone();
            if(gaid){
                newdiv.find('input[class=gaid]').val('');
            }
            newdiv.find('a').html('[-]');
            if(newdiv.find('.is_upload')){
                newdiv.find('.attrimg').attr('src','/static/admin/img/nopic.jpg');
                newdiv.find('.uploaderattr').html('<button type="button" class="btn btn-info btn-sm" onclick="upattrpic(this);">上传图像</button>');
                newdiv.find('.delpic').hide();
                newdiv.find('input[class=attrpic_id]').val('');
                newdiv.find('.repicm').text('');
            }
            group.append(newdiv);
        }else if($(obj).html() == '[-]'){
            if(gaid){
                layer.confirm('该属性已存在，是否彻底删除?', {
                    skin: 'layui-layer-molv',
                    closeBtn: 0,
                    shadeClose : true,
                    btn: ['确定','取消'] //按钮
                },function(){
                    layer.load(2);
                    $.ajax({
                        url:'{:url("goods/deletega")}',
                        type:'POST',
                        data:{'id':gaid,'goods_id':$('input[name=id]').val()},
                        dateType:'json',
                        success:function(data){
                            if(data.status == 1){
                                layer.closeAll('loading');
                                layer.msg(data.mess, {icon: 1,time: 1000}, function(){
                                    div.remove();
                                });
                            }else{
                                layer.closeAll('loading');
                                layer.msg(data.mess, {icon: 2,time: 3000});
                            }
                        },
                        error:function(){
                            layer.closeAll('loading');
                            layer.msg('操作失败，请重试', {icon: 2,time: 2000});
                        }
                    });
                });
            }else{
                div.remove();
            }
        }
    }

    function xzshuxing(obj) {
        var arrValue = $(obj).val();
        $(obj).parent('span').next('span').children('input.ccdd').val(arrValue);
    }

    function cl(){
        location.href = url;
    }

    function upattrpic(obj){
        var div = $(obj).parent().parent();
        var uploaderattr = div.find('.uploaderattr');
        $(obj).remove();

        //上传缩略图
        uploaderattr.Huploadify({
            uploader : '{:url("Common/Upload/uploadPic")}',
            method:'post',
            formData:{name:'goods_attr'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
            buttonText : '上传图像',
            removeTimeout: 2000,
            fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG;',
            fileObjName: 'file', //上传附件$_FILE标识
            fileSizeLimit : 2048,
            //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            auto : true, //开启,自动上传
            multi : false, //开启,多选文件
            //开始上传
            onUploadStart:function(file){
                layer.load(2);
            },
            onUploadSuccess : function(file, data, response) {
                //解析成json对象
                eval('var data='+data);
                if(data.status == 200){
                    var picpath = data.data.path;
                    div.find('.attrimg').attr('src',picpath);
                    div.find('.delpic').show();
                    div.find('input[class=attrpic]').val(picpath);
                }else{
                    layer.msg(data.mess, {icon: 2,time: 2000});
                }
            },
            //上传完成后执行的操作
            onUploadComplete:function(file){
                layer.closeAll('loading');
            },
            //上传错误
            onUploadError : function(file, errorCode, errorMsg, errorString) {
                layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
            }
        });
    }

    $('select[name=integral_cate]').change(function(){
        if ($(this).val() == 1) {
            $('#integral_amount').show();
        } else {
            $('#integral_amount').hide();
        }
    })

</script>

</body>
</html>